package LanQiao._14JavaB;

import javax.naming.spi.DirObjectFactory;
import java.util.*;

public class _7买二赠一 {

    //WA  7/10
    //ps: 超时
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr);
        ArrayList<Integer[]> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new Integer[]{arr[i], i});
        }
        boolean[] visited = new boolean[n];
        int left = n - 2;
        int right = n - 1;
        long count = 0;
        boolean flag = true;
        while (left >= 0 && flag){
            int p1 = arr[left];
            int p2 = arr[right];
            int p;
            p = p1 / 2;
            count += p1 + p2;
            visited[left] = true;
            visited[right] = true;
            Iterator<Integer[]> iterator = list.iterator();
            while (iterator.hasNext()) {
                Integer[] integers = iterator.next();
                if (integers[1] == left || integers[1] == right) {
                    iterator.remove();
                }
            }
            flag = helper(list,p,visited);
            while (right >= 1 && visited[right]){
                right--;
            }
            left = right - 1;
            while (left >= 0 && visited[left]){
                left--;
            }
        }
        while (right>=0){
            if (visited[right]){
                right--;
                continue;
            }
            count += arr[right];
            right--;
        }
        System.out.println(count);
        scan.close();
    }

    public static boolean helper(ArrayList<Integer[]>  list,int p,boolean[] visited){
        int left = 0,right = list.size()-1;

        while (left <= right){
            int mid = left + (right - left) / 2;
            if (list.get(mid)[0] == p){
                visited[list.get(mid)[1]] = true;
                list.remove(mid);
                return true;
            }else if(list.get(mid)[0] < p){
                left = mid + 1;
            }else {
                right = mid - 1;
            }
        }

        if (right >= 0){
            visited[list.get(right)[1]] = true;
            list.remove(right);
            return true;
        }else {
            return false;
        }
    }

}
